package com.bdzl.biz.controller;

import java.util.List;
import java.util.Map;

import com.bdzl.pub.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bdzl.pub.entity.loan.OrderCustDO;
import com.bdzl.biz.service.OrderCustService;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;

/**
 * 融资租赁订单客户信息表
 *
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-05-11 15:23:42
 */

@Controller
@RequestMapping("/bdzl/orderCust")
public class OrderCustController extends BaseController {
	@Autowired
	private OrderCustService orderCustService;

	@GetMapping()
	String OrderCust(){
	    return "bdzl/orderCust/orderCust";
	}

	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<OrderCustDO> orderCustList = orderCustService.list(query);
		int total = orderCustService.count(query);
		PageUtils pageUtils = new PageUtils(orderCustList, total);
		return pageUtils;
	}

	@GetMapping("/add")
	String add(){
	    return "bdzl/orderCust/add";
	}

	@GetMapping("/edit/{custId}")
	String edit(@PathVariable("custId") Integer custId,Model model){
		OrderCustDO orderCust = orderCustService.get(custId);
		model.addAttribute("orderCust", orderCust);
	    return "bdzl/orderCust/edit";
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( OrderCustDO orderCust){
		if(orderCustService.save(orderCust)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( OrderCustDO orderCust){
		orderCustService.update(orderCust);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer custId){
		if(orderCustService.remove(custId)>0){
		return R.ok();
		}
		return R.error();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] custIds){
		orderCustService.batchRemove(custIds);
		return R.ok();
	}

}
